package cn.aylog.test;

import cn.aylog.dao.UserDao;
import cn.aylog.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Demo {
    Logger LOG = LogManager.getLogger(Demo.class);


    @Test
    public void run1() {
        String path = "mybatis.config.xml";
        LOG.info("开始读取资源文件...");
        try(InputStream is = Resources.getResourceAsStream(path)) {
            SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(is);
            SqlSession session = ssf.openSession();
            UserDao mapper = session.getMapper(UserDao.class);
            User user = mapper.selectById(1);
            System.out.println(user);
        }catch (IOException e) {
            System.out.println(e);
        }finally {
            LOG.info("执行结束...");
        }

    }
}
